/*
 * InodeBlocksAdder.h
 *
 *  Created on: May 12, 2010
 *      Author: Lukasz Spintzyk
 */

#ifndef INODEBLOCKSADDER_H_
#define INODEBLOCKSADDER_H_

#ifndef PH_H_
#include "ph.h"
#endif

class SuperBlock;
class BlockManager;

class InodeBlocksAdder {
public:
	InodeBlocksAdder(BlockManager& reader, SuperBlock& sb);
	~InodeBlocksAdder();

    void addBlocksToInode(InodePtr inode, uint32_t start_free_block_num, uint32_t num);

private:


    uint32_t addDirectBlocks(InodePtr inode, uint32_t free_block, uint32_t size);
    uint32_t addOneIndirectBlocks(InodePtr inode, uint32_t free_block, uint32_t size);
    uint32_t addTwoIndirectBlocks(InodePtr inode, uint32_t free_block, uint32_t size);
    uint32_t addThreeIndirectBlocks(InodePtr inode, uint32_t free_block, uint32_t size);

    uint32_t addToBlock(uint32_t block,
						uint32_t free_blocks,
						uint32_t size,
						uint32_t where);

    uint32_t addToIndirectBlock(uint32_t block,
								uint32_t free_block,
								uint32_t size,
								uint32_t indirect_block,
								uint32_t direct_block,
								uint32_t& added_non_leaf_block);

    uint32_t addToDoubleIndirectBlock(uint32_t block,
									  uint32_t free_block,
			   						  uint32_t size,
									  uint32_t block1,
									  uint32_t block2,
			   						  uint32_t entry,
			   						  uint32_t& added_non_leaf_block);

    byte* d_buffer;
    byte* d_buffer2;
    byte* d_buffer3;
    BlockManager& d_reader;
    SuperBlock& d_sb;
};

#endif /* INODEBLOCKSADDER_H_ */
